<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<!--设置一个文本域用于显示信息  -->
	<textarea readonly name="msg" id="msg" cols="30" rows="10">
</textarea>
	<script language=javascript>
		var int = self.setInterval("clock()", 1000)//实现定时刷新，定时调用clock（）函数
		var i=0,j;
		function clock() {
			
			var xmlhttp;
			if (window.XMLHttpRequest) {
				xmlhttp = new XMLHttpRequest();
			} else {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					//获取返回的Json数组，并对其进行解析
					var returnJSONString = xmlhttp.responseText;
					var returnJSON = JSON.parse(returnJSONString);
					//用循环获取每次最新加入的数据
					for (j=i; j < returnJSON.length; i++) {
						
						$("#msg").append(
								"有客户预定了" + returnJSON[i].bookroom_roomtype
										+ ",房间号"
										+ returnJSON[i].bookroom_roomid + ",于"
										+ returnJSON[i].bookroom_liveintime
										+ "入住"+"\n");
					}
				}
			}
			xmlhttp.open("get", "/HotelManagement/ceshi", true);//通过get方法访问ceshi  Servlet
			xmlhttp.send();

		}
	</script>
	<button onclick="int=window.clearInterval(int)">停止接收消息</button>
</body>
</html>